﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Scoreboard.Interfaces;
using System.Collections.Generic;
using Scoreboard.Model;
using System.ServiceModel.DomainServices.Client;
using Scoreboard.Model.Services;

namespace Scoreboard.Repository
{
	public class TournamentRepository : Repository, ITournamentRepository
	{	
		public TournamentRepository(ScoreboardDomainContext context) : base(context)
		{			
		}		

		public void GetTournaments(Action<LoadOperation<Tournament>> callback)
		{
			Context.Load(Context.GetTournamentsQuery(), callback, null);
		}

		public void GetTournament(int id, Action<LoadOperation<Tournament>> callback)
		{
			Context.Load(Context.GetTournamentsQuery().Where(t => t.Id == id), LoadBehavior.RefreshCurrent, callback, null);
		}

		public IEnumerable<Tournament> GetTournamentsLive()
		{
			Context.Load(Context.GetTournamentsQuery());

			return Context.Tournaments;
		}

		public void AddTournament(Tournament tournament)
		{ 			
			Context.Tournaments.Add(tournament);
		}

		public void DeleteTournament(Tournament tournament)
		{
			Context.Tournaments.Remove(tournament);
		}	
	

	}	
}
